package org.zcl.utils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.StringJoiner;

/**
 * .
 *
 * @author zhuchenglin
 * @since 2024/8/3 16:24
 */
public class CommonUtil {

    public static String readFile(String filePath) {
        try {
            List<String> lines = Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8);
            StringBuilder contentBuilder = new StringBuilder();
            for (String line : lines) {
                contentBuilder.append(line).append("\n");
            }
            return contentBuilder.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static void printLog(String message) {
        String log = new StringJoiner("|").add(String.valueOf(System.currentTimeMillis())).add(String.format("%2d", Thread.currentThread().getId())).add(Thread.currentThread().getName()).add(message).toString();
        System.out.println(log);
    }
}
